package com.example.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.b_pojo.Musicarticletag;
import com.example.common.pojo.musictag;
import com.example.dao.MusicArticleMapper;
import com.example.dao.MusicTagMapper;
import com.example.dao.mapper.BMusicarticletagMapper;
import com.example.dao.mapper.BMusictagMapper;
import com.example.service.MusicTagservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class MusicTagserviceImp extends ServiceImpl<MusicTagMapper, musictag> implements MusicTagservice {

    @Autowired
    private BMusictagMapper bmusicTagMapper;

    @Autowired
    private MusicTagMapper musicTagMapper;

    @Autowired
    private BMusicarticletagMapper bmusicArticleTagMapper;

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.example.common.pojo.musictag>
     * @param @param pageNum
    	* @param pageSize
    	* @param name
     * @author znk
     * @date 2024/9/26 15:53
     * 存在逻辑查询
     */
    @Override
    public Page<musictag> selectPageTagandByName(int pageNum, int pageSize, String name) {
        Page<musictag> musictagPage = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<musictag> wapper = new LambdaQueryWrapper<>();
        if(name!=null && !name.trim().isEmpty()){
            wapper.like(musictag::getTagName,name);
        }
        Page<musictag> page = musicTagMapper.selectPage(musictagPage, wapper);
        return page;
    }

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.example.common.pojo.musictag>
     * @param @param pageNum
    	* @param pageSize
    	* @param name
     * @author znk
     * @date 2024/9/27 16:07
     * 不存在逻辑查询
     */
    @Override
    public Page<musictag> selectPageNodelectTagandByName(int pageNum, int pageSize, String name) {
        Page<musictag> musictagPage = new Page<>(pageNum, pageSize);
        HashMap<String, Object> params = new HashMap<>();
        params.put("name",name);
        params.put("pageNum", (pageNum - 1) * pageSize);
        params.put("pageSize", pageSize);
        List<musictag> tags = musicTagMapper.selectPageTagandByName(params);
        musictagPage.setRecords(tags);
        return musictagPage;
    }

    @Override
    public boolean startandstop(Long id) {
        int i=musicTagMapper.startandstop(id);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean removeAllById(Long id) {
        int i=musicTagMapper.removeAllById(id);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean addTagToArticle(Long articleId, Long tagId) {
        int i = bmusicArticleTagMapper.addTagToArticle(articleId, tagId);
        if (i>0){
            return true;
        }
        return false;
    }


}
